home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Essentials / Dynamo 4.2 for GSBug 1.5b10 / dynamo.includes / rtfp.macros < prev    next >
Encoding:
Text File  |  1990-09-21  |  19.5 KB  |  870 lines  |  [TEXT/MPS ]

  1. ***************************************
  2.  
  3.  
  4. * This macro takes the value of a string and returns it in the acc,y.
  5. * If there is no op1, then the string number is assumed to be in the xreg.
  6.     MACRO
  7. &lab    _fstrval    &op
  8. &lab
  9.     if    &op='' goto .jsr
  10.     ldx    #<&op
  11. .jsr    jsr    fstrval
  12.     MEND
  13.  
  14.  
  15. ***************************************
  16.  
  17.  
  18. * This macro takes the value of op1 string starting at op2 character and
  19. * returns it in the acc,y.  If there is no op1, then the string number is
  20. * assumed to be in the xreg.  If there is no op2, then the character number
  21. * is assumed to be in the yreg.
  22.     MACRO
  23. &lab    _fmidstrval &op1,&op2
  24. &lab
  25.     if    &op1='' goto .a
  26.     ldx    #<&op1
  27. .a    if    &op2='' goto .jsr
  28.     ycorm    &op2
  29. .jsr    jsr    fmidstrval
  30.     MEND
  31.  
  32.  
  33. ***************************************
  34.  
  35.  
  36. * This macro reads a float from the current data pointer and advances the
  37. * pointer by five bytes.  If there is no op1, then the destination variable
  38. * number is assumed to be in the xreg.
  39.     MACRO
  40. &lab    _readfloat &op
  41. &lab    
  42.     if    &op='' goto .jsr
  43.     ldx    #<&op
  44. .jsr    jsr    readfloat
  45.     MEND
  46.  
  47.  
  48. ***************************************
  49.  
  50.  
  51. * This macro converts an integer variable into a floating-point variable.
  52.     MACRO
  53. &lab    _i2f    &op
  54. &lab
  55.     if    &op='' goto .jsr
  56.     ldx    #<&op
  57. .jsr    jsr    i2f
  58.     MEND
  59.  
  60.  
  61. ***************************************
  62.  
  63.  
  64. * This macro converts a floating-point variable into an integer variable.
  65.     MACRO
  66. &lab    _f2i    &op
  67. &lab
  68.     if    &op='' goto .jsr
  69.     ldx    #<&op
  70. .jsr    jsr    f2i
  71.     MEND
  72.  
  73.  
  74. ***************************************
  75.  
  76.  
  77. * This macro prints a float value.  fout expects a pointer to the float.
  78. * The pointer is either already in a,y (no operand), or is
  79. * determined by the operand.
  80.     MACRO
  81. &lab    _fout &op
  82. &lab    
  83.     if    &op='' goto .jsr
  84.     fparm    &op
  85.     if    finline=0 goto .jsr
  86.     jsr    frtsout
  87.     _asc2fp    &op
  88.     mexit
  89. .jsr    jsr    fout
  90.     MEND
  91.  
  92.  
  93. ***************************************
  94.  
  95.  
  96. * This macro prints a float value.  This value is stored in a variable.
  97. * The variable number is either already in the xreg (no operand), or is
  98. * determined by the operand.
  99.     MACRO
  100. &lab    _fvout &op
  101. &lab    
  102.     if    &op='' goto .jsr
  103.     ldx    #<&op
  104. .jsr    jsr    fvout
  105.     MEND
  106.  
  107.  
  108. ***************************************
  109.  
  110.  
  111. * This macro multiplies the destination float variable by a float variable.
  112. * If there is no op1, then the destination variable number is assumed to be
  113. * in the xreg.  If there is no op2, then the source variable number is
  114. * assumed to be in the yreg.
  115.     MACRO
  116. &lab    _fmulvar    &op1,&op2
  117. &lab
  118.     if    &op1='' goto .a
  119.     ldx    #<&op1
  120. .a    if    &op2='' goto .jsr
  121.     ldy    #<&op2
  122. .jsr    jsr    fmulvar
  123.     MEND
  124.  
  125.  
  126. ***************************************
  127.  
  128.  
  129. * This macro multiplies the destination float variable by a float constant.
  130. * If there is no op1, then the destination variable number is assumed to be
  131. * in the xreg.  If there is no op2, then the source float pointer is
  132. * assumed to be in a,y.
  133.     MACRO
  134. &lab    _fmul    &op1,&op2
  135. &lab
  136.     if    &op1='' goto .a
  137.     ldx    #<&op1
  138. .a    if    &op2='' goto .jsr
  139.     fparm    &op2
  140.     if    finline=0 goto .jsr
  141.     jsr    frtsmul
  142.     _asc2fp    &op2
  143.     mexit
  144. .jsr    jsr    fmulcon
  145.     MEND
  146.  
  147.  
  148. ***************************************
  149.  
  150.  
  151. * This macro divides the destination float variable by a float variable.
  152. * If there is no op1, then the destination variable number is assumed to be
  153. * in the xreg.  If there is no op2, then the source variable number is
  154. * assumed to be in the yreg.
  155.     MACRO
  156. &lab    _fdivvar    &op1,&op2
  157. &lab
  158.     if    &op1='' goto .a
  159.     ldx    #<&op1
  160. .a    if    &op2='' goto .jsr
  161.     ldy    #<&op2
  162. .jsr    jsr    fdivvar
  163.     MEND
  164.  
  165.  
  166. ***************************************
  167.  
  168.  
  169. * This macro divides the destination float variable by a float constant.
  170. * If there is no op1, then the destination variable number is assumed to be
  171. * in the xreg.  If there is no op2, then the source float pointer is
  172. * assumed to be in a,y.
  173.     MACRO
  174. &lab    _fdiv    &op1,&op2
  175. &lab
  176.     if    &op1='' goto .a
  177.     ldx    #<&op1
  178. .a    if    &op2='' goto .jsr
  179.     fparm    &op2
  180.     if    finline=0 goto .jsr
  181.     jsr    frtsdiv
  182.     _asc2fp    &op2
  183.     mexit
  184. .jsr    jsr    fdivcon
  185.     MEND
  186.  
  187.  
  188. ***************************************
  189.  
  190.  
  191. * This macro adds a float variable to the destination float variable.
  192. * If there is no op1, then the destination variable number is assumed to be
  193. * in the xreg.  If there is no op2, then the source variable number is
  194. * assumed to be in the yreg.
  195.     MACRO
  196. &lab    _faddvar    &op1,&op2
  197. &lab
  198.     if    &op1='' goto .a
  199.     ldx    #<&op1
  200. .a    if    &op2='' goto .jsr
  201.     ldy    #<&op2
  202. .jsr    jsr    faddvar
  203.     MEND
  204.  
  205.  
  206. ***************************************
  207.  
  208.  
  209. * This macro adds a float constant the destination float variable.
  210. * If there is no op1, then the destination variable number is assumed to be
  211. * in the xreg.  If there is no op2, then the source float pointer is
  212. * assumed to be in a,y.
  213.     MACRO
  214. &lab    _fadd    &op1,&op2
  215. &lab
  216.     if    &op1='' goto .a
  217.     ldx    #<&op1
  218. .a    if    &op2='' goto .jsr
  219.     fparm    &op2
  220.     if    finline=0 goto .jsr
  221.     jsr    frtsadd
  222.     _asc2fp    &op2
  223.     mexit
  224. .jsr    jsr    faddcon
  225.     MEND
  226.  
  227.  
  228. ***************************************
  229.  
  230.  
  231. * This macro subtracts a float variable from the destination float variable.
  232. * If there is no op1, then the destination variable number is assumed to be
  233. * in the xreg.  If there is no op2, then the source variable number is
  234. * assumed to be in the yreg.
  235.     MACRO
  236. &lab    _fsubvar    &op1,&op2
  237. &lab
  238.     if    &op1='' goto .a
  239.     ldx    #<&op1
  240. .a    if    &op2='' goto .jsr
  241.     ldy    #<&op2
  242. .jsr    jsr    fsubvar
  243.     MEND
  244.  
  245.  
  246. ***************************************
  247.  
  248.  
  249. * This macro subtracts a float constant from the destination float variable.
  250. * If there is no op1, then the destination variable number is assumed to be
  251. * in the xreg.  If there is no op2, then the source float pointer is
  252. * assumed to be in a,y.
  253.     MACRO
  254. &lab    _fsub    &op1,&op2
  255. &lab
  256.     if    &op1='' goto .a
  257.     ldx    #<&op1
  258. .a    if    &op2='' goto .jsr
  259.     fparm    &op2
  260.     if    finline=0 goto .jsr
  261.     jsr    frtssub
  262.     _asc2fp    &op2
  263.     mexit
  264. .jsr    jsr    fsubcon
  265.     MEND
  266.  
  267.  
  268. ***************************************
  269.  
  270.  
  271. * This macro raises the destination float variable by the source float variable.
  272. * If there is no op1, then the destination variable number is assumed to be in
  273. * the xreg.  If there is no op2, then the source variable number is assumed to
  274. * be in the yreg.
  275.     MACRO
  276. &lab    _fv2v    &op1,&op2
  277. &lab
  278.     if    &op1='' goto .a
  279.     ldx    #<&op1
  280. .a    if    &op2='' goto .jsr
  281.     ldy    #<&op2
  282. .jsr    jsr    fv2v
  283.     MEND
  284.  
  285.  
  286. ***************************************
  287.  
  288.  
  289. * This macro raises the destination float variable by the a float constant.
  290. * If there is no op1, then the destination variable number is assumed to be
  291. * in the xreg.  If there is no op2, then the source float pointer is
  292. * assumed to be in a,y.
  293.     MACRO
  294. &lab    _fv2con    &op1,&op2
  295. &lab
  296.     if    &op1='' goto .a
  297.     ldx    #<&op1
  298. .a    if    &op2='' goto .jsr
  299.     fparm    &op2
  300.     if    finline=0 goto .jsr
  301.     jsr    frtsv2con
  302.     _asc2fp    &op2
  303.     mexit
  304. .jsr    jsr    fv2con
  305.     MEND
  306.  
  307.  
  308.  
  309. ***************************************
  310.  
  311.  
  312. * This macro gets the sign of the destination float variable and stores it in
  313. * the destination variable.  If there is no op, then the destination variable
  314. * number is assumed to be in the xreg.
  315.     MACRO
  316. &lab    _fsgn    &op
  317. &lab
  318.     if    &op='' goto .jsr
  319.     ldx    #<&op
  320. .jsr    jsr    fsgn
  321.     MEND
  322.  
  323.  
  324. ***************************************
  325.  
  326.  
  327. * This macro gets the absolute value of the destination float variable and
  328. * stores it in the destination variable.  If there is no op, then the
  329. * destination variable number is assumed to be in the xreg.
  330.     MACRO
  331. &lab    _fabs    &op
  332. &lab
  333.     if    &op='' goto .jsr
  334.     ldx    #<&op
  335. .jsr    jsr    fabs
  336.     MEND
  337.  
  338.  
  339. ***************************************
  340.  
  341.  
  342. * This macro gets the integer value of the destination float variable and
  343. * stores it in the destination variable.  If there is no op, then the
  344. * destination variable number is assumed to be in the xreg.
  345.     MACRO
  346. &lab    _fint    &op
  347. &lab
  348.     if    &op='' goto .jsr
  349.     ldx    #<&op
  350. .jsr    jsr    fint
  351.     MEND
  352.  
  353.  
  354. ***************************************
  355.  
  356.  
  357. * This macro gets the square root of the destination float variable and
  358. * stores it in the destination variable.  If there is no op, then the
  359. * destination variable number is assumed to be in the xreg.
  360.     MACRO
  361. &lab    _fsqr    &op
  362. &lab
  363.     if    &op='' goto .jsr
  364.     ldx    #<&op
  365. .jsr    jsr    fsqr
  366.     MEND
  367.  
  368.  
  369. ***************************************
  370.  
  371.  
  372. * This macro gets the log base e of the destination float variable and
  373. * stores it in the destination variable.  If there is no op, then the
  374. * destination variable number is assumed to be in the xreg.
  375.     MACRO
  376. &lab    _flog    &op
  377. &lab
  378.     if    &op='' goto .jsr
  379.     ldx    #<&op
  380. .jsr    jsr    flog
  381.     MEND
  382.  
  383.  
  384. ***************************************
  385.  
  386.  
  387. * This macro raises e to the destination float variable power and
  388. * stores it in the destination variable.  If there is no op, then the
  389. * destination variable number is assumed to be in the xreg.
  390.     MACRO
  391. &lab    _fexp    &op
  392. &lab
  393.     if    &op='' goto .jsr
  394.     ldx    #<&op
  395. .jsr    jsr    fexp
  396.     MEND
  397.  
  398.  
  399. ***************************************
  400.  
  401.  
  402. * This macro forms a 'random' number and stores it in the destination
  403. * variable.  If there is no op, then the destination variable number
  404. * is assumed to be in the xreg.
  405.     MACRO
  406. &lab    _frnd    &op
  407. &lab
  408.     if    &op='' goto .jsr
  409.     ldx    #<&op
  410. .jsr    jsr    frnd
  411.     MEND
  412.  
  413.  
  414. ***************************************
  415.  
  416.  
  417. * This macro gets the cos of the destination float variable and
  418. * stores it in the destination variable.  If there is no op, then the
  419. * destination variable number is assumed to be in the xreg.
  420.     MACRO
  421. &lab    _fcos    &op
  422. &lab
  423.     if    &op='' goto .jsr
  424.     ldx    #<&op
  425. .jsr    jsr    fcos
  426.     MEND
  427.  
  428.  
  429. ***************************************
  430.  
  431.  
  432. * This macro gets the sin of the destination float variable and
  433. * stores it in the destination variable.  If there is no op, then the
  434. * destination variable number is assumed to be in the xreg.
  435.     MACRO
  436. &lab    _fsin    &op
  437. &lab
  438.     if    &op='' goto .jsr
  439.     ldx    #<&op
  440. .jsr    jsr    fsin
  441.     MEND
  442.  
  443.  
  444. ***************************************
  445.  
  446.  
  447. * This macro gets the tan of the destination float variable and
  448. * stores it in the destination variable.  If there is no op, then the
  449. * destination variable number is assumed to be in the xreg.
  450.     MACRO
  451. &lab    _ftan    &op
  452. &lab
  453.     if    &op='' goto .jsr
  454.     ldx    #<&op
  455. .jsr    jsr    ftan
  456.     MEND
  457.  
  458.  
  459. ***************************************
  460.  
  461.  
  462. * This macro gets the arctan of the destination float variable and
  463. * stores it in the destination variable.  If there is no op, then the
  464. * destination variable number is assumed to be in the xreg.
  465.     MACRO
  466. &lab    _fatn    &op
  467. &lab
  468.     if    &op='' goto .jsr
  469.     ldx    #<&op
  470. .jsr    jsr    fatn
  471.     MEND
  472.  
  473.  
  474. ***************************************
  475.  
  476.  
  477. * This macro sets a float variable to a 1-byte value.  If there is no op1,
  478. * then the destination variable number is assumed to be in the xreg.  If
  479. * there is no op2, then the value is assumed to be in the acc.
  480.     MACRO
  481. &lab    _i2fsetl    &op1,&op2
  482. &lab    
  483.     if    &op1='' goto .a
  484.     ldx    #<&op1
  485. .a    if    &op2='' goto .jsr
  486.     acorm    &op2
  487. .jsr    jsr    i2fsetconl
  488.     MEND
  489.  
  490.  
  491. ***************************************
  492.  
  493.  
  494. * This macro sets a float variable to a 2-byte value.  If there is no op1,
  495. * then the destination variable number is assumed to be in the xreg.  If
  496. * there is no op2, then the value is assumed to be in the acc.
  497.     MACRO
  498. &lab    _i2fset    &op1,&op2
  499. &lab    
  500.     if    &op1='' goto .a
  501.     ldx    #<&op1
  502. .a    if    &op2='' goto .jsr
  503.     aycorm    &op2
  504.     if    ayisbyte=1 then
  505.     jsr    i2fsetconl
  506.     mexit
  507.     endif
  508. .jsr    jsr    i2fsetcon
  509.     MEND
  510.  
  511.  
  512. ***************************************
  513.  
  514.  
  515. * This macro is used to set a bunch of float variables to integer constant
  516. * values.  There must be a non-zero even number of parameters.  The odd
  517. * parameters are the variables, and the even parameters are the constant
  518. * values for the preceeding parameter.  The setvars routine uses the
  519. * return address as a pointer to the data (just like the write routine).
  520. * It simply sets the designated variable to the designated constant until
  521. * it encounters a 255 as a variable value.  A 255 is reserved for this
  522. * purpose.  This macro places a 255 at the end of the data list
  523. * automatically.
  524.     MACRO
  525. &lab    _i2fsetvars
  526. &lab    
  527.     if    &syslist[2]='' then
  528.     aerror    '_setvars:  must have at least two parameters'
  529.     mexit
  530.     endif
  531.     jsr    i2fsetvars
  532.     lcla    &i,&j,&n
  533. &i    seta    1
  534. &j    seta    2
  535. &n    seta    &nbr(&syslist)
  536. .a    if    &syslist[&j]='' then
  537.     aerror    '_i2fsetvars:  must have even number of parameters'
  538.     mexit
  539.     endif
  540.     dc.b    &syslist[&i]
  541.     if    &substr(&syslist[&j],1,1)<>'#' then
  542.     aerror    '_i2fsetvars:  variables can only be set to constants -- missing #'
  543.     mexit
  544.     endif
  545.     dc.w    &substr(&syslist[&j],2,999)
  546. &i    seta    &i+2
  547. &j    seta    &j+2
  548.     if    &i<=&n goto .a
  549.     dc.b    255
  550.     MEND
  551.  
  552.  
  553. ***************************************
  554.  
  555.  
  556. * This macro is used to set a bunch of float variables to float constant
  557. * values.  There must be a non-zero even number of parameters.  The odd
  558. * parameters are the variables, and the even parameters are the constant
  559. * values for the preceeding parameter.  The setvars routine uses the
  560. * return address as a pointer to the data (just like the write routine).
  561. * It simply sets the designated variable to the designated constant until
  562. * it encounters a 255 as a variable value.  A 255 is reserved for this
  563. * purpose.  This macro places a 255 at the end of the data list
  564. * automatically.
  565.     MACRO
  566. &lab    _fsetvars
  567. &lab    
  568.     if    &syslist[2]='' then
  569.     aerror    '_setvars:  must have at least two parameters'
  570.     mexit
  571.     endif
  572.     jsr    fsetvars
  573.     lcla    &i,&j,&n
  574. &i    seta    1
  575. &j    seta    2
  576. &n    seta    &nbr(&syslist)
  577. .a    if    &syslist[&j]='' then
  578.     aerror    '_fsetvars:  must have even number of parameters'
  579.     mexit
  580.     endif
  581.     dc.b    &syslist[&i]
  582.     if    &substr(&syslist[&j],1,1)<>'#' then
  583.     aerror    '_fsetvars:  variables can only be set to constants -- missing #'
  584.     mexit
  585.     endif
  586.     _asc2fp    &syslist[&j]
  587. &i    seta    &i+2
  588. &j    seta    &j+2
  589.     if    &i<=&n goto .a
  590.     dc.b    255
  591.     MEND
  592.  
  593.  
  594. ***************************************
  595.  
  596.  
  597. * This macro sets the destination float variable to a float constant.
  598. * If there is no op1, then the destination variable number is assumed to be
  599. * in the xreg.  If there is no op2, then the source float pointer is
  600. * assumed to be in a,y.
  601.     MACRO
  602. &lab    _fset    &op1,&op2
  603. &lab
  604.     if    &op1='' goto .a
  605.     ldx    #<&op1
  606. .a    if    &op2='' goto .jsr
  607.     fparm    &op2
  608.     if    finline=0 goto .jsr
  609.     jsr    frtssetcon
  610.     _asc2fp    &op2
  611.     mexit
  612. .jsr    jsr    fsetcon
  613.     MEND
  614.  
  615.  
  616. ***************************************
  617.  
  618.  
  619.     MACRO
  620. &lab    _fset0    &op
  621. &lab
  622.     if    &op='' goto .a
  623.     ldx    #<&op
  624. .a    
  625.     jsr    fsetzero
  626.     MEND
  627.  
  628.  
  629. ***************************************
  630.  
  631.  
  632. * This macro compares the destination float variable with a float variable.
  633. * If there is no op1, then the destination variable number is assumed to be
  634. * in the xreg.  If there is no op2, then the source variable number is
  635. * assumed to be in the yreg.  The equal status is true if the variables are
  636. * equal.  If the xreg variable is greater or equal, then the carry is set.
  637. * If the xreg variable is smaller, then the carry is clear.  
  638.     MACRO
  639. &lab    _fvcmp    &op1,&op2
  640. &lab
  641.     if    &op1='' goto .a
  642.     ldx    #<&op1
  643. .a    if    &op2='' goto .jsr
  644.     ldy    #<&op2
  645. .jsr    jsr    fvcmp
  646.     MEND
  647.  
  648.  
  649. ***************************************
  650.  
  651.  
  652. * This macro compares the destination float variable with a float constant.
  653. * If there is no op1, then the destination variable number is assumed to be
  654. * in the xreg.  If there is no op2, then the source variable number is
  655. * assumed to be in the yreg.  The equal status is true if the values are
  656. * equal.  If the xreg variable is greater or equal, then the carry is set.
  657. * If the xreg variable is smaller, then the carry is clear.  
  658.     MACRO
  659. &lab    _fcmp    &op1,&op2
  660. &lab
  661.     if    &op1='' goto .a
  662.     ldx    #<&op1
  663. .a    if    &op2='' goto .jsr
  664.     fparm    &op2
  665.     if    finline=0 goto .jsr
  666.     jsr    frtscmp
  667.     _asc2fp    &op2
  668.     mexit
  669. .jsr    jsr    fcmp
  670.     MEND
  671.  
  672.  
  673. ***************************************
  674.  
  675.  
  676. * This macro sets a float variable to another float variable.  If there is
  677. * no op1, then the destination variable number is assumed to be in the
  678. * xreg.  If there is no op2, then the source variable number is assumed
  679. * to be in the yreg.
  680.     MACRO
  681. &lab    _fvarcpy    &op1,&op2
  682. &lab    
  683.     if    &op1='' goto .a
  684.     ldx    #<&op1
  685. .a    if    &op2='' goto .jsr
  686.     ldy    #<&op2
  687. .jsr    jsr    fvarcpy
  688.     MEND
  689.  
  690.  
  691. ***************************************
  692. ***************************************
  693. ***************************************
  694.  
  695.  
  696. * This macro generates an AppleSoft floating-point number.
  697.     MACRO
  698. &lab    _asc2fp    &op
  699.     lcla    &exp,&mant            ;Exponent and mantissa portions.
  700.     lclc    &str
  701. &str    setc    &op                ;We can't modify the parm, so copy it.
  702. &lab
  703.     if    &substr(&str,1,1)='#' goto .const
  704.     aerror    'floating-point constant parameter must start with a #'
  705.     mexit
  706. .const
  707. &str    setc    &substr(&str,2,999)        ;Get rid of #.
  708.  
  709.     lcla    &sgn                ;Get sign of number.
  710. &sgn    seta    $80000000            ;Assume positive.
  711.     if    &substr(&str,1,1)='-' then
  712. &sgn    seta    0
  713. &str    setc    &substr(&str,2,999)        ;Get rid of -.
  714.     endif
  715.  
  716.     if    &substr(&str,1,1)='+' then        ;Get rid of optional +.
  717. &str    setc    &substr(&str,2,999)
  718.     endif
  719.  
  720.  
  721.  
  722.     lcla    &dptflg,&dptcnt            ;Setup work values.
  723. &dptflg    seta    0                ;Decimal-point flag.
  724. &dptcnt    seta    0                ;Decimal-point count.
  725.     lclc    &c,&s                ;Work character and string.
  726. &s    setc    ''
  727.  
  728.  
  729.  
  730. * This loop moves digits into &s, looks for a decimal-point, and
  731. * counts digits after a decimal-point.
  732.  
  733. .loop1
  734. &c    setc    &substr(&str,1,1)            ;Get left-most character.
  735.     if    &c='' goto .brk1            ;End of string.
  736. &str    setc    &substr(&str,2,999)
  737.     if    &c<'0' goto .b            ;Not digit.
  738.     if    &c>'9' goto .b            ;Not digit.
  739.  
  740. &s    setc    &concat(&s,&c)            ;Collect the digit.
  741.     if    &dptflg=1 then
  742. &dptcnt    seta    &dptcnt+1            ;Count digits right of decimal.
  743.     endif
  744.     goto    .loop1
  745.  
  746. .b    if    &c<>'.' goto .c
  747.     if    &dptflg=1 then
  748.     aerror    'bad floating-point constant'    ;Don't allow 2 decimal-points.
  749.     endif
  750. &dptflg    seta    1                ;Flag that we found first decimal-point.
  751.     goto    .loop1
  752.  
  753. .c    if    &c='e' goto .brk1            ;At exponent part.
  754.     if    &c='E' goto .brk1            ;At exponent part.
  755.     aerror    'bad floating-point constant'    ;Any other character is an error.
  756.     mexit
  757. .brk1
  758.  
  759. &mant    seta    &strtoint(&s)            ;Convert digits into a 4-byte integer.
  760.  
  761.     if    &mant=0 then            ;Special-case for 0.
  762.     dc.b    0,0,0,0,0
  763.     mexit
  764.     endif
  765.  
  766. &exp    seta    128+32                ;Normalize the number.
  767. .loop2    if    &mant<0 goto .brk2
  768. &exp    seta    &exp-1
  769. &mant    seta    &mant<<1
  770.     goto    .loop2
  771. .brk2
  772.  
  773.     lcla    &expval,&expneg
  774. &expval    seta    0                ;Default exponent value is 0.
  775. &expneg    seta    0                ;Assume positive.
  776.     if    &str='' goto .doexp        ;We have no exponent part.
  777.  
  778.     if    &substr(&str,1,1)='-' then        ;Check sign of exponent.
  779. &expneg    seta    1
  780. &str    setc    &substr(&str,2,999)        ;Get rid of -.
  781.     endif
  782.  
  783.     if    &substr(&str,1,1)='+' then
  784. &str    setc    &substr(&str,2,999)        ;Get rid of optional +.
  785.     endif
  786.  
  787. &expval    seta    &strtoint(&str)            ;Get the exponent value.
  788.     if    &expneg=1 then
  789. &expval    seta    -&expval
  790.     endif
  791.  
  792. .doexp                        ;Process exponent portion.
  793.     lcla    &num,&mantlo,&manthi,&test        ;Use this as a work variable.
  794. &expval    seta    &expval-&dptcnt            ;Subtract frac digits from exponent.
  795.     if    &expval=0 goto .out        ;No exponent adjustment.
  796.     if    &expval<0 goto .div10        ;Negative exponent adjustment.
  797.  
  798. .mul10
  799. &mantlo    seta    &mant**$00FFFFFF            ;Break mantissa into lo and hi parts.
  800. &manthi    seta    &mant**$FF000000
  801. &manthi    seta    &manthi>>1
  802. &manthi    seta    &manthi**$7FFFFFFF
  803. &manthi    seta    &manthi>>7
  804. &mantlo    seta    &mantlo*10            ;Multiply mantissa by 10.
  805. &manthi    seta    &manthi*10
  806. .ma    
  807. &test    seta    &manthi**$FF000000
  808.     if    &test=0 goto .mb
  809. &exp    seta    &exp+1
  810. &num    seta    &mantlo**$01            ;Keep this for rounding later.
  811. &manthi    seta    &manthi>>1
  812. &manthi    seta    &manthi**$7FFFFFFF
  813. &mantlo    seta    &mantlo>>1
  814.     goto    .ma
  815. .mb
  816. &manthi    seta    &manthi<<8
  817. &mant    seta    &manthi+&mantlo+&num
  818.     if    &mant<0 goto .mc
  819. &mant    seta    $FFFFFFFF
  820. .mc
  821. &expval    seta    &expval-1
  822.     if    &expval>0 goto .mul10        ;More multiplies.
  823.     goto    .out                ;Finally, go do it.
  824.  
  825. .div10                        ;Keep as much precision as possible.
  826. &mantlo    seta    &mant>>1                ;Break mantissa into lo and hi parts.
  827. &mantlo    seta    &mantlo**$7FFFFFFF
  828. &mantlo    seta    &mantlo/1280
  829. &mantlo    seta    &mantlo*2560
  830. &mantlo    seta    &mant-&mantlo
  831. &manthi    seta    &mant-&mantlo
  832. &mantlo    seta    &mantlo<<8
  833.  
  834. &mantlo    seta    &mantlo/10            ;Divide mantissa by 10.
  835. &manthi    seta    &manthi>>1
  836. &manthi    seta    &manthi**$7FFFFFFF
  837. &manthi    seta    &manthi/5
  838.  
  839. .da    if    &manthi<0 goto .db
  840. &exp    seta    &exp-1
  841. &manthi    seta    &manthi<<1
  842. &mantlo    seta    &mantlo<<1
  843.     goto    .da
  844. .db
  845. &mantlo    seta    &mantlo>>7
  846. &num    seta    &mantlo**$01
  847. &mantlo    seta    &mantlo>>1
  848. &mant    seta    &manthi+&mantlo+&num
  849.     if    &mant<0 goto .dc            ;Final add didn't cause problems.
  850. &mant    seta    $FFFFFFFF
  851. .dc
  852. &expval    seta    &expval+1
  853.     if    &expval<0 goto .div10        ;More divides.
  854.  
  855. .out                        ;Finally, do it.
  856. &mant    seta    &mant--&sgn            ;Pack the sign into the mantissa.
  857.     lcla    &m0,&m1,&m2,&m3
  858. &m0    seta    &mant**$FF
  859. &mant    seta    &mant>>8
  860. &mant    seta    &mant**$00FFFFFF
  861. &m1    seta    &mant**$FF
  862. &mant    seta    &mant>>8
  863. &m2    seta    &mant**$FF
  864. &m3    seta    &mant>>8
  865.  
  866.     dc.b    &exp,&m3,&m2,&m1,&m0        ;Generate the code.
  867.  
  868.     mend
  869.  
  870.